# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

_setmiscver=0.33
_ndkver=0.3.2

pkgbase=nginx-mod-ndk-set-misc
pkgname=(nginx-mod-ndk nginx-mod-set-misc)
pkgver=$_setmiscver+$_ndkver
pkgrel=4

arch=('loong64' 'x86_64')
depends=('nginx')
makedepends=('nginx-src')
url="https://github.com/openresty/set-misc-nginx-module"
license=('BSD')

source=(
	https://github.com/openresty/set-misc-nginx-module/archive/v$_setmiscver/set-misc-$_setmiscver.tar.gz
	https://github.com/simpl/ngx_devel_kit/archive/v$_ndkver/ngx_devel_kit-$_ndkver.tar.gz
)
validpgpkeys=(B0F4253373F8F6F510D42178520A9993A1C052F8) # Maxim Dounin <mdounin@mdounin.ru>
sha256sums=('cd5e2cc834bcfa30149e7511f2b5a2183baf0b70dc091af717a89a64e44a2985'
            'aa961eafb8317e0eb8da37eb6e2c9ff42267edd18b56947384e719b85188f58b')

prepare() {
	mkdir -p build
	cd build
	ln -sf /usr/src/nginx/auto
	ln -sf /usr/src/nginx/src
}

build() {
	cd build
	/usr/src/nginx/configure --with-compat \
	  --add-dynamic-module=../ngx_devel_kit-$_ndkver \
	  --add-dynamic-module=../set-misc-nginx-module-$_setmiscver
	make modules
}

package_nginx-mod-ndk() {
	pkgdesc="Nginx module that adds additional generic tools that module developers can use in their own modules"

	cd build/objs
	install -Dm755 ndk_http_module.so "$pkgdir"/usr/lib/nginx/modules/ndk_http_module.so

	cd "$srcdir"/ngx_devel_kit-$_ndkver
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_nginx-mod-set-misc() {
	pkgdesc="Nginx module that adds various set_xxx directives"
	depends=("nginx" 'nginx-mod-ndk')

	cd build/objs
	install -Dm755 ngx_http_set_misc_module.so "$pkgdir"/usr/lib/nginx/modules/ngx_http_set_misc_module.so

	install -Dm644 "$srcdir"/set-misc-nginx-module-$_setmiscver/README.markdown \
	               "$pkgdir"/usr/share/licenses/$pkgname/README.markdown
}
